<?php
/*
	我的足迹
*/
defined('BY_JYA') or exit('error');
$this->model('member')->checklogin();
$return['ice_menu_array']=array( array('menu_key' => 'index', 'menu_name' => '收货地址', 'menu_url' => custom_url('jy_weishop/member.address/',true)) );
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['item']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=pdo_getall('core_address',array('mid'=>$_SESSION['uid']));
	foreach($return['list'] as &$item){
			$item['pcd']=@json_decode($item['pcd'],true);
	}
	exi($return);
}
if($_RQ['op']=='post'){
	$id=$_RQ['id'];
	if($id){
		$return['address']=pdo_get('core_address',array('id'=>$id))	;
		$return['address']['pcd']=@json_decode($return['address']['pcd'],true);
	}
	$return['province']=cfc('tools')->pcd();
	exi($return);
}
if($_RQ['op']=='save'){
	$post=get_postdata();
	
	$data=array('name'=>$post['name'],'pcd'=>ijson_encode($post['pcd']),'mobile'=>$post['mobile'],'address'=>$post['address']);
	if($post['id']){
		pdo_update('core_address',$data,array('id'=>$post['id']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];$data['mid']=$_SESSION['uid'];
		pdo_insert('core_address',$data);
	}
	
	exi('保存成功','','/member.address/');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要设置的地址','error');
	}
	pdo_update('core_address',array('isdefault'=>0),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'isdefault'=>1));
	pdo_update('core_address',array('isdefault'=>1),array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('设置成功','','/member.address/');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要删除的地址','error');
	}
	pdo_delete('core_address',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if($_RQ['get']==1){
		exi('success');
	}else{
		exi('删除成功','','/member.address/');
	}
}
